package com.song.tools.songtest.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.song.tools.core.util.ObjectUtils;
import com.song.tools.mvc.manager.BaseManager;
import com.song.tools.songtest.beans.bo.SysRoleBo;
import com.song.tools.songtest.beans.query.SysRoleQuery;
import com.song.tools.songtest.convertor.SysRoleConvertor;
import com.song.tools.songtest.dao.entity.SysRole;
import com.song.tools.songtest.dao.mapper.SysRoleMapper;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 角色表 管理类
 * </p>
 *
 * @author song tools
 * @since 2024-07-09
 */
@Component
public class SysRoleManager extends BaseManager<SysRole, SysRoleBo, SysRoleMapper, SysRoleQuery, Long, SysRoleConvertor> {

    @Override
    public LambdaQueryWrapper<SysRole> encapsulateQueryWrapper(SysRoleQuery query) {
        LambdaQueryWrapper<SysRole> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCode()), SysRole::getCode, query.getCode());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRoleName()), SysRole::getRoleName, query.getRoleName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRemark()), SysRole::getRemark, query.getRemark());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getCreateTimeStart()), SysRole::getCreateTime, query.getCreateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getCreateTimeEnd()), SysRole::getCreateTime, query.getCreateTimeEnd());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysRole::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysRole::getUpdateTime, query.getUpdateTimeEnd());

        return queryWrapper;
    }
}
